// nodejs中间件功能实现

const middleware = []
let mw1 = async function (ctx, next) {
    console.log("next前，第一个中间件")
    await next()
    console.log("next后，第一个中间件")
}
let mw2 = async function (ctx, next) {
    console.log("next前，第二个中间件")
    await next()
    console.log("next后，第二个中间件")
}
let mw3 = async function (ctx, next) {
    console.log("第三个中间件，没有next了")
}

function use(mw) {
  middleware.push(mw);
}

function compose(middleware) {
  return (ctx, next) => {
    return dispatch(0);
    function dispatch(i) {
      const fn = middleware[i];
      if (!fn) return;
      return fn(ctx, dispatch.bind(null, i+1));
    }
  }
}

use(mw1);
use(mw2);
use(mw3);

const fn = compose(middleware);

fn();

const l = console.log
function add(a){
	l(a,new Number(10))
}
let a = add.bind(null,5)
let c = add.bind(null,7)
let arr = [254,545]
let b = add.bind(null,6)
let obj = {'sdkfj':1,obj:25}
let set = new Set([4654,564,564,56,456])
let ma = new Map([['15',154]])

add.call(10,5)
